package ${appProperty.basePackage}.service.impl;

import com.autonavi.abs.common.base.PageResult;
import ${appProperty.basePackage}.model.dto.${tableMeta.upperName}DTO;
import ${appProperty.basePackage}.model.query.${tableMeta.upperName}Query;
import ${appProperty.basePackage}.dao.${tableMeta.upperName}DAO;
import ${appProperty.basePackage}.service.${tableMeta.upperName}Service;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;

/**
* @author ${appProperty.author}
* @version V1.0
* <p>Description: ${tableMeta.upperName} ServiceImpl</p>
* @date ${appProperty.dateTime}
*/
@Service(value = "${tableMeta.camelName}Service")
public class ${tableMeta.upperName}ServiceImpl implements ${tableMeta.upperName}Service {

    @Autowired
    private ${tableMeta.upperName}DAO ${tableMeta.camelName}DAO;

    @Override
    public boolean insert(${tableMeta.upperName}DTO ${tableMeta.camelName}DTO){
        return ${tableMeta.camelName}DAO.insert(${tableMeta.camelName}DTO) > 0;
    }

    @Override
    public boolean deleteById(Long id){
        return ${tableMeta.camelName}DAO.deleteById(id) > 0;
    }

    @Override
    public boolean updateById(${tableMeta.upperName}DTO ${tableMeta.camelName}DTO){
        return ${tableMeta.camelName}DAO.updateById(${tableMeta.camelName}DTO) > 0;
    }

    @Override
    public ${tableMeta.upperName}DTO selectById(Long id){
        return ${tableMeta.camelName}DAO.selectById(id);
    }

    @Override
    public List<${tableMeta.upperName}DTO> selectByQuery(${tableMeta.upperName}Query query){
        return ${tableMeta.camelName}DAO.selectByQuery(query);
    }

    @Override
    public PageResult<${tableMeta.upperName}DTO> selectPageByQuery(${tableMeta.upperName}Query query){
        PageResult result = new PageResult();
        int totalCount = ${tableMeta.camelName}DAO.selectCountByQuery(query);
        int totalPage = (totalCount + query.getPageSize() - 1) / query.getPageSize();
        int pageNum = query.getPageIndex();
        int pageSize = query.getPageSize();
        Integer offset = (pageNum - 1) * pageSize;
        query.setOffset(offset);
        query.setLimit(pageSize);
        List<${tableMeta.upperName}DTO> list = ${tableMeta.camelName}DAO.selectPageByQuery(query);
        result.setCurrentPage(pageNum);
        result.setPageSize(pageSize);
        result.setPages(totalPage);
        result.setTotalCount(totalCount);
        result.setDatas(list);
        return result;
    }

}
